#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
    FILE *myfp;

    if (argc != 2) {
        printf("error: Please input \"%s, file\"\n", argv[0]);
    }

    if( (myfp = fopen(argv[1], "aw")) == NULL ) {
        perror("Failed to open this file!");
    } else {
        fprintf(myfp, "This is a test!\n");
    }

    // 由于标准输出是行缓冲的，而标准错误是不缓冲的，因此a/b has ... 会出现在a/b之前
    fprintf(stdout, "a");
    fprintf(stderr, "a has been writeen\n");
    fprintf(stdout, "b");
    fprintf(stderr, "b has been writeen\n");
    fprintf(stdout, "\n");

    return 0;
}